package com.ruozedata.bigdata.lesson03

object ConstructApp {

    def main(args: Array[String]): Unit = {

        val person = new Person("Pk", 20)
        println(s"${person.age}, name is ${person.name}")

        val p2 = new Person("pk2", 19, "ddd")
        println(p2)

        println(".................................")

        val student = new Student("A1", 18, "CS")
        println(s"school is ${student.school} name is ${student.name}")

        println(student.toString) // 默认：包名+类名@hash
    }
}

/**
 * class 类名(...) 在Scala是主构造器
 *
 * val优先 不行再上var
 * 默认把括号中对应的转换为属性
 */
class Person(val name:String, val age:Int) {
    println("Person INto。。。")

    val school:String = "pku"
    var gender:String = _

    /**
     * todo 代码不全
     * 附属构造器
     * 1）def this 定义的叫附属构造器
     * 2）一个附属构造器第一行必须调用主构造器或其他附属构造器
     */
    def this(name:String, age:Int, gender:String) {
        this(name, age) // 调用主构造器
        this.gender = gender

    }

    println("person ....OUt")
}

/**
 * 继承
 * 先调用父类构造器 再调用子构造器
 */
class Student(name:String, age:Int, val major:String) extends Person(name, age) {
    println("Student into....")

    // 属性覆盖
    override val school: String = "pku2"
    // 方法重写
    override def toString: String = "super.toString"

    println("Student OUt.......")
}
